<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-08-05 15:16:04
 * @LastEditTime : 2020-01-14 10:02:39
 * @LastEditors  : Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../../css/base.css" />
    <script type="text/javascript" src="../../script/jquery.js"></script>
    <script type="text/javascript" src="../../script/layer/mobile/layer.js"></script>
    <script type="text/javascript" src="../../script/vue.min.js"></script>
    <script type="text/javascript" src="../../script/vant.min.js"></script>
    <script type="text/javascript" src="../../script/fastclick.js"></script>
    <script type="text/javascript" src="../../script/base.js"></script>
    <style type="text/css">
        .row {
            margin-top: 10px;
            position: relative;
        }

        .row:last-child {
            margin-bottom: 10px;
        }

        .row .delete {
            position: absolute;
            left: 0;
            width: 0;
            top: 0;
            bottom: 0;
            text-align: center;
            line-height: 68px;
            background: #fff;
            transition: all .4s;
        }

        .row .delete img {
            width: 25px;
        }

        .showDelete {
            width: 40px !important;
        }

        .row-info {
            margin-left: 0;
            overflow: hidden;
            width: 100%;
            transition: all .4s;
        }

        .m-r {
            margin-left: 40px;
        }

        .ov {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            font-size: 14px;
        }

        /* .van-cell__value {
            text-align: right;
        } */

        .label {
            font-weight: 500;
            font-size: 13px;
            color: #969799;
        }

        .seal {
            width: 60px;
            top: 0;
            right: 0;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="init-full">
            <van-nav-bar class="head" title="历史单据" left-arrow @click-left="onClickLeft">
                <div slot="right" class="head-right">
                    <span @click="isEditDraft = !isEditDraft;"
                        v-show="type == 101 && tabActive != 2">{{isEditDraft?'完成':'编辑'}}</span>
                    <span @click="showSearch = true;">
                        <img src="../../image/search.png" />
                    </span>
                </div>
            </van-nav-bar>
            <div class="body-no-bottom">
                <div class="content">
                    <van-tabs v-model="tabActive" v-if="type == 101 || type == 401 || type == 71">
                        <van-tab :title="type == 101?'草稿':'待处理'" v-if="type != 71">
                            <van-list v-model="listLoading1" :finished="listFinished1" finished-text="没有更多了"
                                @load="listOnLoad(1)">
                                <div class="row" v-for="(row,index) in dataList1" @click="intoRow(row)">
                                    <div class="delete" :class="isEditDraft?'showDelete':''"
                                        @click.stop="deleteDraft(row,index)">
                                        <!-- <van-icon name="delete" color="#cd1b21" size="26px"></van-icon> -->
                                        <img src="../../image/delete_row.png" />
                                    </div>
                                    <div class="row-info" :class="isEditDraft?'m-r':''">
                                        <van-cell clickable>
                                            <div>
                                                <van-row gutter="20">
                                                    <van-col span="14" class="ov">
                                                        {{type == 71?row.StockName:row.ClientName}}</van-col>
                                                    <van-col span="10">{{row.BillDate}}</van-col>
                                                </van-row>
                                            </div>
                                            <div class="label">
                                                <van-row gutter="20">
                                                    <van-col span="14" v-if="type == 101">合计数量:{{parseInt(row.SumNum)}}
                                                    </van-col>
                                                    <van-col span="14" v-if="type == 71">经手人:{{row.Creater}}
                                                    </van-col>
                                                    <van-col span="10" v-if="type != 71">合计金额:{{row.SumMoney}}</van-col>
                                                </van-row>
                                            </div>

                                            <img class="seal" :src="getSealImage(row)" v-if="row.IsPayZT!=0" />
                                        </van-cell>
                                    </div>


                                </div>
                            </van-list>
                        </van-tab>
                        <van-tab title="未过账">
                            <van-list v-model="listLoading2" :finished="listFinished2" finished-text="没有更多了"
                                @load="listOnLoad(2)">
                                <div class="row" v-for="(row,index) in dataList2" @click="intoRow(row)">
                                    <div class="delete" :class="isEditDraft?'showDelete':''"
                                        @click.stop="deleteDraft(row,index)">
                                        <!-- <van-icon name="delete" color="#cd1b21" size="26px"></van-icon> -->
                                        <img src="../../image/delete_row.png" />
                                    </div>
                                    <div class="row-info" :class="isEditDraft?'m-r':''">
                                        <van-cell clickable>
                                            <div>
                                                <van-row gutter="20">
                                                    <van-col span="14" class="ov">
                                                        {{type == 71?row.StockName:row.ClientName}}</van-col>
                                                    <van-col span="10">{{row.BillDate}}</van-col>
                                                </van-row>
                                            </div>
                                            <div class="label">
                                                <van-row gutter="20">
                                                    <van-col span="14" v-if="type == 101">合计数量:{{parseInt(row.SumNum)}}
                                                    </van-col>
                                                    <van-col span="14" v-if="type == 71">经手人:{{row.Creater}}
                                                    </van-col>
                                                    <van-col span="10" v-if="type != 71">合计金额:{{row.SumMoney}}</van-col>
                                                </van-row>
                                            </div>
                                            <img class="seal" :src="getSealImage(row)" v-if="row.IsPayZT!=0" />
                                        </van-cell>
                                    </div>
                                </div>
                            </van-list>
                        </van-tab>
                        <van-tab title="已过账">
                            <van-list v-model="listLoading3" :finished="listFinished3" finished-text="没有更多了"
                                @load="listOnLoad(3)">
                                <div class="row" v-for="(row,index) in dataList3" @click="intoRow(row)">
                                    <!-- <div class="delete" :class="isEditDraft?'showDelete':''"
                                        @click.stop="deleteDraft(row,index)">
                                        <img src="../../image/delete_row.png" />
                                    </div> -->
                                    <div class="row-info">
                                        <van-cell clickable>
                                            <div>
                                                <van-row gutter="20">
                                                    <van-col span="14" class="ov">
                                                        {{type == 71?row.StockName:row.ClientName}}</van-col>
                                                    <van-col span="10">{{row.BillDate}}</van-col>
                                                </van-row>
                                            </div>
                                            <div class="label">
                                                <van-row gutter="20">
                                                    <van-col span="14" v-if="type == 101">合计数量:{{parseInt(row.SumNum)}}
                                                    </van-col>
                                                    <van-col span="14" v-if="type == 71">经手人:{{row.Creater}}
                                                    </van-col>
                                                    <van-col span="10" v-if="type != 71">合计金额:{{row.SumMoney}}</van-col>
                                                </van-row>
                                            </div>
                                            <img class="seal" :src="getSealImage(row)" v-if="row.IsPayZT!=0" />
                                        </van-cell>
                                    </div>
                                </div>

                            </van-list>
                        </van-tab>
                    </van-tabs>

                    <div v-if="type == 92 || type == 93">
                        <van-list v-model="listLoading3" :finished="listFinished3" finished-text="没有更多了"
                            @load="listOnLoad(3)">
                            <div class="row" v-for="(row,index) in dataList3" @click="intoRow(row)">
                                <van-cell clickable>
                                    <div>
                                        <van-row gutter="20">
                                            <van-col span="14" class="ov">{{row.ClientName}}</van-col>
                                            <van-col span="10">{{row.BillDate}}</van-col>
                                        </van-row>
                                    </div>
                                    <div class="label">
                                        <van-row gutter="20" v-if="type == 92">
                                            <van-col span="14">合计进价:{{row.N_SumMoney}}</van-col>
                                            <van-col span="10">合计售价:{{row.SumMoney}}</van-col>
                                        </van-row>
                                        <van-row gutter="20" v-if="type == 93">
                                            <van-col span="14">活动套餐:{{row.ProjectName}}</van-col>
                                            <van-col span="10">充值金额:{{row.RecMoney}}</van-col>

                                        </van-row>
                                    </div>
                                </van-cell>
                            </div>
                        </van-list>
                    </div>
                </div>
                <van-loading v-if="showLoading" />
            </div>
        </div>

        <van-popup v-model="showSearch" round position="bottom">
            <div>
                <van-cell title="往来单位" :value="searchData.S_ClientName" is-link @click="openScreen(-1,10)">
                </van-cell>
                <van-cell title="开始时间" :value="searchData.S_SDate" @click="openDate(1)">
                </van-cell>
                <van-cell title="结束时间" :value="searchData.S_EDate" @click="openDate(2)">
                </van-cell>
            </div>
            <div class="btn-padding">
                <van-button type="primary" block style="border-radius: 0;" @click="searchList">查询</van-button>
            </div>
        </van-popup>


        <van-popup v-model="showDate" round position="bottom">
            <van-datetime-picker v-model="currentDate" type="date" @confirm="confirmDate" @cancel="cancelDate"
                cancel-button-text="清空" />
        </van-popup>
    </div>
</body>

<script type="text/javascript">
    var vm;
    apiready = function () {
        //$('.init-full').show();

        api.addEventListener({
            name: 'keyback'
        }, function (ret, err) {
            vm.onClickLeft();
        });

        api.addEventListener({
            name: 'selectRow'
        }, function (ret, err) {
            var selectType = ret.value.selectType;
            var type = ret.value.type;
            var row = ret.value.row;
            if (selectType == 10) {
                if (row) {
                    vm.searchData.S_ClientName = row.name;
                    vm.searchData.S_ClientID = row.id;
                } else {
                    vm.searchData.S_ClientName = '';
                    vm.searchData.S_ClientID = 0;
                }

            }

        });

        api.addEventListener({
            name: 'refreshList'
        }, function (ret, err) {
            var type = ret.value.type;
            vm['pageIndex' + type] = 1;
            var obj = {
                S_B_Type: type,
                S_BillType: vm.type,
                S_Pageindex: vm['pageIndex' + type],
                S_PageSize: vm['pageSize' + type],
                S_ClientID: vm.searchData.S_ClientID,
                S_BranchID: vm.searchData.S_BranchID,
                S_SDate: vm.searchData.S_SDate,
                S_EDate: vm.searchData.S_EDate
            }
            FLD.ajax('AP_HisList_B', obj, function (res) {
                vm['listFinished' + type] = false;
                vm['dataList' + type] = res.ds;
            })
        })
        var type = api.pageParam.type;
        var tabActive = api.pageParam.tabActive === undefined ? 1 : api.pageParam.tabActive;
        var userInfo = FLD.getUserInfo();
        var dateIndex = 0;
        vm = new Vue({
            el: '#app',
            data: {
                showLoading: false,
                showSearch: false,
                type: type,
                tabActive: parseInt(tabActive),
                isEditDraft: false,
                listLoading1: false,
                listFinished1: true,
                listLoading2: false,
                listFinished2: true,
                listLoading3: false,
                listFinished3: true,
                dataList1: [],
                dataList2: [],
                dataList3: [],
                pageIndex1: 1,
                pageSize1: 20,
                pageIndex2: 1,
                pageSize2: 20,
                pageIndex3: 1,
                pageSize3: 20,
                currentDate: new Date(),
                showDate: false,
                searchData: {
                    S_ClientID: 0,
                    S_ClientName: '',
                    S_BranchID: userInfo.S_BranchID,
                    S_SDate: '',
                    S_EDate: ''
                }

            },
            created: function () {
                this.getList();
            },
            methods: {
                getList() {
                    var that = this;
                    that.showLoading = true;
                    var obj1 = {
                        S_B_Type: 1,
                        S_BillType: that.type,
                        S_Pageindex: that.pageIndex1,
                        S_PageSize: that.pageSize1,
                        S_ClientID: that.searchData.S_ClientID,
                        S_BranchID: that.searchData.S_BranchID,
                        S_SDate: that.searchData.S_SDate,
                        S_EDate: that.searchData.S_EDate
                    }
                    FLD.ajax('AP_HisList_B', obj1, function (res) {
                        that.showLoading = false;
                        that.listFinished1 = false;
                        that.dataList1 = res.ds;
                    })
                    var obj2 = {
                        S_B_Type: 2,
                        S_BillType: that.type,
                        S_Pageindex: that.pageIndex2,
                        S_PageSize: that.pageSize2,
                        S_ClientID: that.searchData.S_ClientID,
                        S_BranchID: that.searchData.S_BranchID,
                        S_SDate: that.searchData.S_SDate,
                        S_EDate: that.searchData.S_EDate
                    }
                    FLD.ajax('AP_HisList_B', obj2, function (res) {
                        that.showLoading = false;
                        that.listFinished2 = false;
                        that.dataList2 = res.ds;
                        console.log(JSON.stringify(res.ds))
                    })
                    var obj3 = {
                        S_B_Type: 3,
                        S_BillType: that.type,
                        S_Pageindex: that.pageIndex3,
                        S_PageSize: that.pageSize3,
                        S_ClientID: that.searchData.S_ClientID,
                        S_BranchID: that.searchData.S_BranchID,
                        S_SDate: that.searchData.S_SDate,
                        S_EDate: that.searchData.S_EDate

                    }
                    FLD.ajax('AP_HisList_B', obj3, function (res) {
                        that.showLoading = false;
                        that.listFinished3 = false;
                        that.dataList3 = res.ds;
                    })
                },
                listOnLoad(index) {
                    var that = this;
                    that['pageIndex' + index]++;
                    var obj = {
                        S_B_Type: index,
                        S_BillType: that.type,
                        S_Pageindex: that['pageIndex' + index],
                        S_PageSize: that['pageSize' + index],
                        S_ClientID: that.searchData.S_ClientID,
                        S_BranchID: that.searchData.S_BranchID,
                        S_SDate: that.searchData.S_SDate,
                        S_EDate: that.searchData.S_EDate
                    }
                    FLD.ajax('AP_HisList_B', obj, function (res) {
                        that['listLoading' + index] = false;
                        if (res.ds.length == 0) {
                            that['listFinished' + index] = true;
                        }
                        that['dataList' + index] = that['dataList' + index].concat(res.ds);
                    })
                },
                getSealImage(row) {
                    if (row.IsPayZT == 1) {
                        return '../../image/confirmed.png';
                    }
                    if (row.IsPayZT == 2) {
                        return '../../image/paying.png';
                    }
                    if (row.IsPayZT == 3) {
                        return '../../image/payed.png';
                    }
                },
                searchList() {
                    var that = this;
                    that.showSearch = false;

                    that.pageIndex1 = 1;
                    that.pageIndex2 = 1;
                    that.pageIndex3 = 1;

                    this.getList();
                },
                deleteDraft(row, index) {
                    var that = this;
                    this.$dialog.confirm({
                        title: '提示',
                        message: '是否删除该条记录?'
                    }).then(() => {
                        if (that.tabActive == 0) {
                            FLD.ajax('APP_DraftDEL', { S_DraftID: row.BillID }, function (res) {
                                that.dataList1.splice(index, 1);
                                layer.open({
                                    content: '删除成功',
                                    skin: 'msg',
                                    time: 2
                                });
                            })
                        } else {
                            var obj = {
                                S_BillID: row.BillID,
                                S_BillType: 101
                            }
                            FLD.ajax('APP_StockBOLDel', obj, function (res) {
                                if (res.ds[0].status == 200) {
                                    that.dataList2.splice(index, 1);
                                    layer.open({
                                        content: '删除成功',
                                        skin: 'msg',
                                        time: 2
                                    });
                                } else {
                                    layer.open({
                                        content: res.ds[0].msg,
                                        skin: 'msg',
                                        time: 2
                                    });
                                }

                            })
                        }

                    }).catch(() => {

                    });

                },
                openScreen(type, index) {
                    var obj = {
                        S_Type: index,
                        S_Cont: '',
                        S_BranchID: userInfo.S_BranchID,
                        S_SXZ: '',
                        S_StockID: userInfo.S_StockID,
                        S_CargoID: userInfo.S_CargoID,
                        S_BarCode: '',
                        S_PriceN: 0,
                        S_ProductID: 0
                    }

                    api.openWin({
                        name: '筛选' + index,
                        url: 'baseScreen.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: {
                            filterData: obj,
                            type: type,
                            allowClear: true
                        }
                    })

                },
                openDate(index) {
                    dateIndex = index;
                    this.currentDate = new Date()
                    this.showDate = true;
                },
                confirmDate(value) {
                    if (dateIndex == 1) {
                        this.searchData.S_SDate = FLD.getFormatDate(value).split(' ')[0]
                    } else {
                        this.searchData.S_EDate = FLD.getFormatDate(value).split(' ')[0]
                    }
                    this.showDate = false;
                },
                cancelDate(value) {
                    if (dateIndex == 1) {
                        this.searchData.S_SDate = ''
                    } else {
                        this.searchData.S_EDate = '';
                    }
                    this.showDate = false;
                },
                intoRow(row) {
                    if (this.type == 101) {
                        if (this.tabActive == 2) {
                            api.openWin({
                                name: 'sellingPrint',
                                url: '../sellingPrint.html',
                                reload: true,
                                slidBackEnabled: false,
                                pageParam: {
                                    historyData: row
                                }
                            })
                        } else {
                            api.openWin({
                                name: 'selling',
                                url: '../selling.html',
                                reload: true,
                                slidBackEnabled: false,
                                pageParam: {
                                    historyData: row
                                }
                            })
                        }

                    } else if (this.type == 401) {
                        api.openWin({
                            name: 'receipt',
                            url: '../receipt.html',
                            reload: true,
                            slidBackEnabled: false,
                            pageParam: {
                                historyData: row
                            }
                        })
                    } else if (this.type == 92) {
                        api.openWin({
                            name: 'seasoningCondiments',
                            url: '../seasoningCondiments.html',
                            reload: true,
                            slidBackEnabled: false,
                            pageParam: {
                                historyData: row
                            }
                        })
                    } else if (this.type == 93) {
                        api.openWin({
                            name: 'activityRecharge',
                            url: '../activityRecharge.html',
                            reload: true,
                            slidBackEnabled: false,
                            pageParam: {
                                historyData: row
                            }
                        })
                    } else if (this.type == 71) {
                        api.openWin({
                            name: 'stockTaking',
                            url: '../stockTaking.html',
                            reload: true,
                            slidBackEnabled: false,
                            pageParam: {
                                historyData: row
                            }
                        })
                    }

                },
                onClickLeft() {
                    api.sendEvent({
                        name: 'setOrientation'
                    });
                    api.closeWin();
                }
            }
        })
    };
</script>

</html>